<template>
	<view class="pop-order-remark">
		<u-popup :show="show_pop" bgColor="#ffffff" :closeable="false" :closeOnClickOverlay="true" round="40"
			@close="onClose" @open="onOpen">

			<view class="info-modal-wrap">
				<view class="info-modal-inner">
					<view class="modal-head flex-center">
						<view class="title-box">
							优惠券
						</view>
					</view>
					<view class="modal-ctx">
						<scroll-view class="scroll" scroll-y="true">
							<view class="box">
								<view class="tip">
									请选择优惠券
								</view>
								<view class="list" v-if="coupons && coupons.length">
									<view class="item flex-between" v-for="(item,index) in coupons" :key="index"
										@click="toggle_coupon(item)">
										<view class="info-left">
											<view class="title ellipsis-1">
												{{item.jian_price}}元优惠券 ({{item.tiaojian}})
											</view>
											<view class="desc" @click.stop="to_view_content(item)">
												查看使用条款与条件
											</view>
										</view>
										<view class="info-right">
											<radio :value="String(item.id)" :checked="couponSelect.id === item.id"
												activeBackgroundColor="#CB0011" style="transform:scale(0.7)" />
										</view>
									</view>
								</view>

								<view class="empty-wrap" v-else>
									<w_empty emptyText="暂无可用优惠券" />
								</view>

							</view>
						</scroll-view>

					</view>
					<view class="modal-foot">
						<view class="footer-wrap ">
							<view class="btns">
								<view class="btn  flex-center" @click="not_use_coupon()">
									不使用优惠券
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</u-popup>

		<coupon_content_pop ref="coupon_content_pop" @confirm="confirm_coupon_use" />
	</view>
</template>

<script>
	import coupon_content_pop from '@/components/coupon/coupon_content_pop.vue'

	import {
		mapState
	} from 'vuex'
	export default {
		components: {
			coupon_content_pop
		},
		data() {
			return {
				show_pop: false,
				coupons: [],
				couponSelect: {},
			}
		},
		computed: {
			...mapState([
				//
				''
			]),
		},
		watch: {

		},
		methods: {
			init(coupons) {
				console.log('选择优惠券')
				this.coupons = coupons || [];
				this.show_pop = true;
			},
			onClose() {
				this.show_pop = false;
			},
			onOpen() {},


			to_view_content(item) {
				this.$refs.coupon_content_pop.init(item)
			},
			confirm_coupon_use(item) {
				this.couponSelect = item
			},


			toggle_coupon(item) {
				this.couponSelect = item
				this.show_pop = false;
				this.$emit('confirm', this.couponSelect)
			},

			doConfirm() {
				// this.toBack()
			},

			not_use_coupon() {
				this.show_pop = false
				this.couponSelect = {}
				this.$emit('confirm', this.couponSelect)
			},



			doClose() {
				this.show_pop = false;
			},
			doCouponPick(item) {
				this.coupon_select = item;
			},
			doCancel() {
				this.coupon_select = {};
				this.$emit('confrim', {})
				this.show_pop = false;
			},
			doConfirm() {
				if (!this.coupon_select.id) {
					this.$alert('请选择优惠券')
					return
				}
				this.$emit('confrim', this.coupon_select)
				this.show_pop = false;
			},

			doConfirmPay() {

			},

		},
	}
</script>

<style lang="scss" scoped>
	.scroll-container {
		max-height: calc(100vh - 600rpx);

	}


	.list {
		padding: 24rpx 32rpx;

		.item {
			margin-bottom: 24rpx;
			min-height: 156rpx;
			padding: 0 24rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 4rpx 16rpx 2rpx rgba(0, 0, 0, 0.06);
			border-radius: 8rpx 8rpx 8rpx 8rpx;

			.info-left {
				.title {
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 28rpx;
					color: #000000;
				}

				.desc {
					padding-top: 16rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #8B8C9F;
				}
			}

			.info-right {}
		}
	}


	.pop-order-remark {
		position: relative;
		z-index: 1000;
	}


	.info-modal-wrap {
		width: 100%;
		position: relative;
		text-align: left;
		padding-bottom: 0;
		// padding-bottom: calc(64rpx + constant(safe-area-inset-bottom));
		// padding-bottom: calc(64rpx + env(safe-area-inset-bottom));

		.info-modal-inner {
			border-radius: 16rpx;
			overflow: hidden;
			width: 100%;
			padding: 0 0;
			padding-bottom: 0;
			min-height: 400rpx;
			background: #FFFFFF;
		}
	}



	.modal-head {
		padding: 20rpx 40rpx;

		// border: 1rpx solid #DDDDDD;
		border-bottom: 2rpx solid #F3F4F8;
		padding-right: 0;

		.title-box {}
	}

	.modal-ctx {
		width: 100%;
		background-color: #fff;
		padding: 24rpx 32rpx;
		padding: 0;
		min-height: 500rpx;
		padding-bottom: 30rpx;
	}



	.tip {
		padding: 24rpx 32rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #000000;
	}



	.footer-wrap {
		padding: 20rpx;

		.safe-fixed-bottom {
			position: relative;
		}

		.btns {
			.btn {
				flex: 1;
				width: 100%;
				height: 80rpx;
				background: #CB0011;
				border-radius: 40rpx 40rpx 40rpx 40rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #FFFFFF;
			}
		}
	}
</style>